package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.anno.Log;
import com.itheima.anno.Power;
import com.itheima.mapper.BookMapper;
import com.itheima.pojo.Book;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.User;
import com.itheima.service.BookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Slf4j
public class BookServiceImpl implements BookService {
    @Autowired
    private BookMapper bookMapper;


    @Override
    public PageBean page(Integer page, Integer pageSize, String name, String author, String press) {
        PageHelper.startPage(page, pageSize);
        List<Book> userList = bookMapper.pageHelper(name, author, press);
        Page<Book> p = (Page<Book>) userList;
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }
    @Log
    @Override
    public void insertBook(Book book) {
        book.setCreateTime(LocalDateTime.now());
        book.setUpdateTime(LocalDateTime.now());
        bookMapper.insert(book);
    }
    @Log
    @Override
    public void updateBook(Book book) {
        book.setUpdateTime(LocalDateTime.now());
        bookMapper.update(book);
    }

    @Override
    public Book getById(Integer id) {

        return bookMapper.getById(id);
    }
    @Log
    @Override
    public void deleteById(List<Integer> ids) {
        bookMapper.delete(ids);
    }

}
